//
//  ListPageViewController.swift
//  fruit-helper-swift
//
//  Created by 赵隆杰 on 2022/6/27.
//

import UIKit
import WMPageController

class ListPageViewController: WMPageController {
    
//    var typeNames: [String] = ["清单", "完成"]

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    override init(viewControllerClasses classes: [AnyClass], andTheirTitles titles: [String]) {
        super.init(viewControllerClasses: classes, andTheirTitles: titles)
        
        menuViewStyle = .line
        titleColorSelected = kThemeColor
        titleColorNormal = kColor666666
        menuItemWidth = 100
        delegate = self
        dataSource = self
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension ListPageViewController {
    override func numbersOfChildControllers(in pageController: WMPageController) -> Int {
        return titles!.count
    }
    override func pageController(_ pageController: WMPageController, titleAt index: Int) -> String {
        return titles![index]
    }
    override func pageController(_ pageController: WMPageController, viewControllerAt index: Int) -> UIViewController {
        let listVc = ListViewController.init(typeId: String(index))
        return listVc
    }
    override func pageController(_ pageController: WMPageController, preferredFrameFor menuView: WMMenuView) -> CGRect {
        return CGRect(x: 0, y: 0, width: view.width, height: 44)
    }
    override func pageController(_ pageController: WMPageController, preferredFrameForContentView contentView: WMScrollView) -> CGRect {
//        let menuviewFrame = self.pageController(pageController, preferredFrameFor: self.menuView!)
//        let originY = menuviewFrame.maxY
        return CGRect(x: 0, y: 44.0, width: view.width, height: view.height - 44.0)
    }
}
